package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyServiceImpl implements IStrategyService {
    @Autowired
    private StrategyMapper mapper;

    @Override
    public PageInfo<Strategy> selectList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = mapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<Strategy> selectAll() {

        return mapper.selectAll();
    }


    @Override
    public void saveOrUpdate(Strategy strategy) {
        if (strategy.getId() == null){
            mapper.insert(strategy);
        }else {
            mapper.updateByPrimaryKey(strategy);
        }
    }

    @Override
    public List<Strategy> selectEnable() {
        return mapper.selectEnable();
    }

    @Override
    public List<Strategy> listCommend() {
        return mapper.selectCommend();
    }

}
